#include "soaUploadFileServer.h"

#include <iostream>
#include <thread>
#include "public_define.h"
#include "adr_component.h"
#include "file_uploader.h"

using namespace DcAdr;

SoaUploadFileServer::SoaUploadFileServer()
{

}

SoaUploadFileServer::~SoaUploadFileServer()
{

}

SoaUploadFileServer &SoaUploadFileServer::getInstance()
{
    static SoaUploadFileServer info;
    return info;
}

void SoaUploadFileServer::setPublishHandle(adr_component *component)
{
    m_component = component;
}

void SoaUploadFileServer::Ntf_UploadFile(const std::string &topic, const std::string &requestData, std::string &replyData)
{
    Log_Info("[SoaUploadFileServer] [Ntf_UploadFile]");

    Soa::PB_Basc_DCFileUpload_Ntf_UploadFile_In uploadFile;
    if (!uploadFile.ParsePartialFromString(requestData))
    {
        Log_ERROR("[SoaUploadFileServer] [Ntf_UploadFile] parse proto data failed , topic: {}", topic);
    }

    std::string taskId = uploadFile.taskid();
    std::string eventCode = uploadFile.eventcode();
    std::string files = uploadFile.files();

    Soa::PB_Basc_DCFileUpload_Ntf_UploadFile_Out uploadFileOut;
    uploadFileOut.mutable_return_()->set_code(2001);

    FileUploader tmp;
    tmp.uploadFile(taskId, files, eventCode);

    uploadFileOut.SerializePartialToString(&replyData);

    return;
}